package com.atguigu3.common_algorithm.exer5;

/**
 * @author lhl
 * @date 2025/3/31 11:34
 */
public class ArrayExer05 {
    public static void main(String[] args) {
        int[] arr = new int[]{34,54,3,2,65,7,34,5,76,34,67};
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "\t");
        }
        System.out.println();
        //反转操作(方式1)
//        for (int i = 0; i < arr.length / 2; i++) {
//            int temp = arr[i];
//            arr[i] = arr[arr.length - 1 - i];
//            arr[arr.length - 1 - i] = temp;
//        }

        //方式2
        for (int i = 0,j = arr.length - 1; i < j ; i++,j--) {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }

        //方式3:不推荐
//        int[] newArr = new int[arr.length];
//        for (int i = arr.length - 1; i >= 0; i--) {
//            newArr[arr.length - 1 - i] = arr[i];
//        }
//
//        arr = newArr;

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "\t");
        }



    }
}
